home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / NIFTY / myCShell / idle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-29  |  5.8 KB  |  237 lines  |  [TEXT/KAHL]

  1. /*********************************************************
  2.  "idle.c"
  3.  
  4.  by John A. Love, III [ Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #include <Balloons.h>
  11.  
  12. #include "protos"
  13.  
  14. #include "globals.h"
  15. #include "extern.h"
  16.  
  17. #include "about.h"
  18. #include "floatingWindow.h"
  19.  
  20.  
  21.  
  22.  
  23. void        SetEnable (MenuHandle menu, short item, Boolean enabled);
  24. Boolean        daMenu (void);
  25.  
  26.  
  27.     #define                wholeMenu    0
  28.     extern Boolean        currEdit;                // in "menu.c"
  29.     extern Boolean        currAppWind;            // in "window.c"
  30.     extern long            Sleep;                    // in "event.c"
  31.     extern DialogPtr    helpPtr;                // in "about.c" ...
  32.     extern HelpInfoHdl    hHTBL;
  33.     extern short        First_Menu, Last_Menu;
  34.  
  35.  
  36.  
  37.     
  38. void DoPeriodic (void)    {
  39.  
  40.  
  41.     if (!gWNE)        SystemTask;
  42.  
  43.     gMac2 = TestForColor(&gColorDepth);
  44.     if (Sleep == 1)        Sleep = GetCaretTime();        // Reset after special effects.
  45.     PeriodicWindows();                    // Feeds PeriodicMenus & HandleCursor ...
  46.     PeriodicMenus();
  47.     HandleCursor();
  48.     
  49.     if (gInForeGround)
  50.     {
  51.         gBalloonsUp = BalloonsOn();
  52.         FindAndShowDynamicBalloons(gBalloonsUp);
  53.         
  54.         // Problems with "Switch-A-Roo" ...
  55.         // It eliminates my Help MENU item. }
  56.         //
  57.         // For some ??? reason the next two IFs are required here
  58.         // even though "SetupMainMenus" would NOT have a non-NIL
  59.         // Help MenuHandle unless they were true.
  60.         if (HelpManagerActive())
  61.             if (HMGetHelpMenuHandle(&gHelpMenu) == noErr)
  62.                 if (gHelpMenu != nil)
  63.                     if (CountMItems(gHelpMenu) == gOrigNumHelpItems)
  64.                         AppendMenu(gHelpMenu, "\pAbout my application ...");
  65.     }
  66.     else        gStartBalloons = BalloonsOn();        // Stab me in the back !!
  67.  
  68. }    /* DoPeriodic */
  69.  
  70.  
  71.  
  72. /* -------------------
  73. ** To be or NOT to be !!
  74. ** ------------------- */
  75.  
  76. void    SetEnable (MenuHandle menu, short item, Boolean enabled)    {
  77.  
  78.  
  79.     if (enabled)    EnableItem(menu, item);
  80.     else            DisableItem(menu, item);
  81.  
  82. }    /* SetEnable */
  83.  
  84.  
  85.  
  86. /* -----------------------------------------------------------------
  87. ** PeriodicMenus is called before action is taken on menu commands
  88. ** to correctly enable or disable the "Edit" Menu in case a Desk
  89. ** Accessory owns the front window or no window is up, respectively.
  90. ** The latter also affects individual items in the other Menu(s).
  91. ** ----------------------------------------------------------------- */
  92.  
  93. void PeriodicMenus (void)    {
  94.  
  95.         Boolean            myAppWind;
  96.         Boolean            redraw = false;                // Initialized EVERY time !!
  97.  
  98.  
  99.     /* MultiFinder switches our MENUs out to a different layer. */
  100.     if (!gInForeGround)        return;
  101.     
  102.     /* PeriodicHelp() handles MENUs if the HTBL window is in front: */
  103.     if (PeriodicHelp())        return;
  104.     
  105.     myAppWind = (gFW != nil) && (!gCurrDA);
  106.  
  107.  // SetEnable(gFileMenu, NewWindowItem, !gCurrDA);
  108.  
  109.     if (myAppWind != currAppWind)                /* No need to repeat yourself !! */
  110.     {
  111.         EnableItem(gFileMenu, wholeMenu);
  112.         redraw = true;
  113.         currAppWind = myAppWind;                /* Reset. */
  114.     }
  115.  
  116.  // SetEnable(gFileMenu, CloseWindowItem, myAppWind);
  117.  
  118.     if ((myAppWind || gCurrDA) != currEdit)        /* Avoid a flickering Menu Bar. */
  119.     {
  120.         if (myAppWind || gCurrDA)    EnableItem(gEditMenu, wholeMenu);
  121.         else                        DisableItem(gEditMenu, wholeMenu);
  122.         ;
  123.         currEdit = myAppWind || gCurrDA;        /* Reset. */
  124.         redraw = true;
  125.     }
  126.     
  127.     if (redraw)        DrawMenuBar();
  128.  
  129. }    /* PeriodicMenus */
  130.  
  131.  
  132.  
  133. Boolean        daMenu (void)    {
  134. /* I know ... NEVER assume knowledge of Menu Record structures ... BUT ... */
  135.  
  136.         #define    MenuListLoc        0xA1C
  137.  
  138.         typedef    struct    rMenuRec    {
  139.             MenuHandle    menuOH;
  140.             short        menuLeft;            /* Left edge of Menu. */
  141.         }    rMenuRec;
  142.  
  143.         typedef    struct    hMenuRec    {
  144.             MenuHandle    menuHOH;
  145.             short        reserved;
  146.         }    hMenuRec;
  147.  
  148.         typedef    struct    MenuList    {
  149.             short            lastMenu;        /* Offset to last regular MenuHandle. */
  150.             short            lastRight;        /* Right edge of last Menu's title. */
  151.             short            mbResID;
  152.             rMenuRec        rMenu[];
  153.         //    The following fields are also present:
  154.         //
  155.         //    short            lastHMenu;    --    Offset from here to last
  156.         //                                    hierarchical Menu.
  157.         //    PixMapHandle    menuTitleSave;
  158.         //    hMenuRec        hMenu[];    --    When my daMenu routine is called,
  159.         //                                    there are NO hierarchical Menus.
  160.         }    MenuList, *MenuListPtr, **MenuListHdl;
  161.  
  162.  
  163.         MenuListHdl        MLHdl = (MenuListHdl) (* (longPtr)(MenuListLoc) );
  164.         short            nbrMenusX6, menuCounter, theMenuID;
  165.         
  166.  
  167.     nbrMenusX6 = (*MLHdl)->lastMenu;
  168.     menuCounter = (nbrMenusX6 / 6) - 1;
  169.  
  170.     while (menuCounter >= 0)
  171.     {
  172.         theMenuID = (* (*MLHdl)->rMenu[menuCounter].menuOH )->menuID;
  173.     //    Watch out !!! with System 7 ...
  174.     //    ... the Help Menu (kHMHelpMenuID = -16490) &
  175.     //    ... the Application Menu (ID = ???)
  176.         if ((theMenuID < 0) && (theMenuID >= -16384))    break;
  177.         --menuCounter;
  178.     }    /* scanning the MenuBar */
  179.  
  180.     //    I could have used
  181.     //            daMenu = theMenuID < 0;
  182.     //    because I KNOW my app has menus.  However, to make this routine
  183.     //    applicable to ANY app, what if ANY app had zip menus and there
  184.     //    were no DA menus, I would have to initialize with
  185.     //            theMenuID = 0;
  186.     //    putting an extra statement in a time-critical "doPeriodic" loop.
  187.     return (menuCounter >= 0);
  188.  
  189. }    /* daMenu */
  190.  
  191.  
  192.  
  193. void    PeriodicWindows (void)    {
  194.         
  195.         
  196.     /* Used by HandleCursor and other routines: */
  197.     gFW = TFrontWindow(anyKind);
  198.     gCurrDA = (TFrontWindow(systemKind) != nil) ||    daMenu();
  199.  
  200. }    /* PeriodicWindows */
  201.  
  202.  
  203.  
  204. Boolean    PeriodicHelp (void)    {
  205. /* Handles MENUs if Help Window is in front. */
  206.  
  207.         short            theMenuID;
  208.         static Boolean    HjustActivated = false;        // Initialized ONLY once !!
  209.         
  210.         
  211.     if ((helpPtr == nil) || !((WindowPeek)helpPtr)->hilited)    {
  212.         HjustActivated = false;
  213.         return (false);
  214.     }
  215.     else    {
  216.         if (!HjustActivated)        /* Don't stutter !! */    {
  217.             for (theMenuID = First_Menu; theMenuID <= Last_Menu; theMenuID++)
  218.                 DisableItem(GetMHandle(theMenuID), wholeMenu);
  219.             DrawMenuBar();
  220.             ;
  221.             // Set globals to opposite so MenuBar is re-drawn
  222.             // when Help Window is closed or de-activated:
  223.             currEdit = !currEdit;
  224.             currAppWind = !currAppWind;
  225.             ;
  226.             HjustActivated = true;
  227.         }
  228.         return (true);
  229.     }
  230.  
  231. }    /* PeriodicHelp */
  232.  
  233.  
  234.  
  235.  
  236. /*    { end file "idle.c" }  */
  237.